package com.hushao.aimi.bo;

import com.hushao.aimi.vo.ProductSpecVo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description: 购物车
 * @author: 胡少
 * @create: 2018-06-23 22:46
 **/
@Data
@Slf4j
public class CartBo  {
    /**
     * 购物车id
     */
    private String cartId;
    /**
     * 商品id
     */

    private String productId;

    /**
     * 商品名称
     */
    private String productName;

    /**
     * 商品标题
     */
    private String productTitle;


    private ProductSpecVo productSpecVo;

    /**
     * 购买数量
     */
    private Integer number;

    private CartBo() {

    }

    public static CartBo getCartBo(Object o) {
        CartBo cartBo=new CartBo();
        try{
            Object[] row = (Object[]) o;
            cartBo.cartId = (String) row[0];
            cartBo.productId = (String) row[1];
            cartBo.productName = (String) row[2];
            cartBo.productTitle = (String) row[3];
            cartBo.productSpecVo= new ProductSpecVo((String)row[4],(String)row[5],(String)row[6],(BigDecimal)row[7]);
            cartBo.number = (Integer) row[8];
        }catch (Exception e){log.error("转换错误");}
        return cartBo;

    }


    public CartBo(String productTitle, ProductSpecVo productSpecVo, Integer number) {
        this.productTitle = productTitle;
        this.productSpecVo = productSpecVo;
        this.number = number;
    }

    public static List<CartBo> getCartBo(List<CartBo> cartBos) {

        return  cartBos.stream().map(c->new CartBo(c.getProductTitle(),c.getProductSpecVo(),c.getNumber())).collect(Collectors.toList());

    }


}
